/**
 * 基本设置store
 */
import { makeAutoObservable, computed } from "mobx";
import _ from "lodash";

import {
  ITBadResp,
  ITDesinger,
  ITWorkbench,
  ITDesignerReagent,
  ITDReactReagent,
} from "./interfaces";

import {
  fetchAddDesigner,
  fetchAllDesigner,
  fetchDelDesigner,
  fetchDesignerInfo,
  fetchUpdateDesigner,
  fetchAddDesignerReagent,
  fetchUpdateDesignerReagent,
  fetchDelDesignerReagent,
  fetchDeleteDesignerReactorReagent,
  //   fetchAddReactorReagent,
  fetchClearDesignerReactorReagent,
  fetchUpdateReactorReagent,
  fetchCopyReactorReagent,
  fetchExportDesigner,
  fetchCopyDesigner,
  fetchReactorStep,
  fetchCreateReactExcel,
  fetchCreateReactDesigner,
  fetchReactDesignerList,
  fetchUpdateReactDesigner,
  fetchDelReactDesigner,
  fetchGetReactDesignerById
} from "../api/designer";

import math, { FIXEDINDEX } from "../utils/math";
import { checkResonse } from "../api";

interface ITReactorReagent {
  id: string;
  mmol: number;
  weight: number;
  volume: number;
  amount?: number;
  type?: number;
}

const sortDesignerStep = (data: any) => {
  const { reactors = [] } = data;
  if (reactors && reactors.length) {
    const tempReactor = [...reactors];
    let sortReactor = _.sortBy(tempReactor, "step");
    data.reactors = sortReactor;
  }
  return data;
};

export interface ITDesignerStore {
  // 新增编辑实验设计loading
  addEditDesignerLoading: boolean;

  // 修改新增编辑实验设计loading
  changeAddEditDesignerLoading: (data: boolean) => void;

  // 新增实验设计
  addDesigner: (data: any) => Promise<ITBadResp | null>;

  // 更新实验设计
  updateDesigner: (data: any) => Promise<ITBadResp | null>;

  // 所有实验设计
  allDesigner: ITDesinger[];

  // 修改所有实验设计
  changeAllDesigner: (data: ITDesinger[]) => void;

  // 所有实验设计请求状态
  allDesignerLoading: boolean;

  // 修改所有实验设计请求状态
  changeAllDesignerLoading: (data: boolean) => void;

  // 请求所有实验设计
  getAllDesigner: () => Promise<ITBadResp | null>;

  getAllDesignerList: () => Promise<ITBadResp | any[]>;

  // 删除设计请求状态
  delDesignerLoading: boolean;

  // 修改删除实验设计
  changeDelDesignerLoading: (data: boolean) => void;

  // 删除实验设计
  delDesigner: (data: any) => Promise<ITBadResp | null>;

  // 当前实验设计信息
  currentDesigner: ITDesinger | null;

  // 修改当前实验设计信息
  changeCurrentDesigner: (data: any) => void;

  // 请求当前实验设计详情状态
  currentDesignerLoading: boolean;

  // 修改请求当前实验设计详情状态
  changgeCurrentDesignerLoading: (data: boolean) => void;

  // 当前反应试剂信息
  currentReactorReagents: ITDReactReagent[];

  // 修改当前反应的试剂信息
  changeCurrentReagentorReagent: (data: ITDReactReagent[]) => void;

  // 请求实验设计详情
  getDesignerInfo: (data: any) => Promise<ITBadResp | null>;

  getDesignerDetail: (data: any) => Promise<ITDesinger | null>;

  // 当前工作台信息
  currentWorkbench: ITWorkbench | null;

  // 修改当前工作台信息
  changeCurrentWorkbench: (data: ITWorkbench | null) => void;

  // 当前工作台插槽信息
  currentSlotInfo: any;

  // 修改当前工作台插槽信息
  changeCurrentSlotInfo: (data: any) => void;

  // 存储插槽信息
  saveSlotInfo: (data: any) => Promise<ITBadResp | null>;

  // 清除插槽信息
  removeSlotInfo: (slotname: string) => Promise<ITBadResp | null>;

  // 当前工作台反应台信息
  currentReactorSlotInfo: any;

  // 修改当前工作台反应台信息
  changeCurrentReactorSlotInfo: (data: any) => void;

  // 存储反应插槽信息
  saveReactorSlotInfo: (data: any) => Promise<ITBadResp | null>;

  // 清除插槽信息
  removeReactorSlotInfo: () => Promise<ITBadResp | null>;

  // 当前实验设计试剂信息
  currentReagentsInfo: ITDesignerReagent | null;

  // 修改当前实验设计试剂信息
  changeCurrentReagentsInfo: (data: ITDesignerReagent | null) => void;

  // 保存试剂请求状态
  addEditReagentLoading: boolean;

  // 修改保存试剂请求状态
  changeAddEditReagentLoading: (data: boolean) => void;

  // 保存试剂信息
  addReagents: (data: any) => Promise<ITBadResp | null>;

  // 更新试剂信息
  updateReagents: (data: any) => Promise<ITBadResp | null>;

  // 清除试剂信息
  removeReagent: (data: any) => Promise<ITBadResp | null>;

  // 新增，修改，删除反应试剂请求状态
  reactorReagentLoading: boolean;

  // 修改新增，修改，删除反应试剂请求状态
  changeReactorReagentLoading: (data: boolean) => void;

  // 新增反应试剂信息
  //   addReactorReagent: (data: any) => Promise<ITBadResp | null>;

  // 清除实验试剂
  clearReactorReagen: (data: any) => Promise<ITBadResp | null>;

  // 删除反应试剂
  delDataReactorReagent: (data: any) => Promise<ITBadResp | null>;

  // 编辑反应试剂
  updateReactorReagent: (data: any) => Promise<ITBadResp | null>;

  // 复制反应试剂
  copyReactorReagent: (data: any) => Promise<ITBadResp | null>;

  // 是否显示添加，编辑试剂弹窗
  showReagentAddEditModal: boolean;

  // 修改是否显示添加，编辑试剂弹窗
  changShowReagentAddEditModal: (data: boolean) => void;

  // 添加，编辑试剂弹窗信息
  reagentAddEditData: any;

  // 修改添加，编辑试剂弹窗信息
  changeReagentAddEditData: (data: any) => void;

  // 是否显示编辑反应试剂弹窗
  showReactorReagentDataModal: boolean;

  // 修改是否显示编辑反应试剂弹窗
  changeShowReactorReagentDataModal: (data: boolean) => void;

  // 编辑的反应试剂信息
  editReactorReagentData: ITDReactReagent | null;

  // 修改编辑的反应试剂信息
  changeEditReactorReagentData: (data: ITDReactReagent | null) => void;

  // 计算反应试剂信息
  reactorReagents: ITReactorReagent[];

  // 显示实验详情drawer
  showDesingerDetail: boolean;

  // 修改显示实验详情drawer
  changeShowDesingerDetail: (data: boolean) => void;

  // 导出实验数据
  exportDesinger: (
    data: any,
    callback: () => void
  ) => Promise<ITBadResp | null>;

  // 复制实验设计
  copyDesigner: (data: any) => Promise<ITBadResp | null>;

  // 修改反应步骤
  changeReactorStep: (data: any) => Promise<ITBadResp | null>;

  // 创建反应设计excel文件
  createReactorExcel: (
    data: any,
    callback?: () => void
  ) => Promise<ITBadResp | null>;

  reactionDesignerList: any[];
  changeReactionDesignerList: (data: any) => void;

  // 新增反应设计
  createReactDesigner: (data: any) => Promise<ITBadResp | null>;

  // 删除反应设计
  delReactDesigner: (data: any) => Promise<ITBadResp | null>;

  updateReactDesigner: (data: any) => Promise<ITBadResp | null>;

  getReactDesignById: (data: any) => Promise<ITBadResp | any>;

  getReactDesignerList: (data: any) => Promise<ITBadResp | any[]>;

  openReactionDrawer: boolean;
  changeOpenReactionDrawer: (data: boolean) => void;

  reactionDrawerData: any;
  changeReactionDrawerData: (data: any) => void;
}

class DesignerStore {
  constructor() {
    makeAutoObservable(
      this,
      {
        reactorReagents: computed,
      },
      { autoBind: true }
    );
  }

  // 新增编辑实验设计loading
  addEditDesignerLoading = false;

  // 修改新增编辑实验设计loading
  changeAddEditDesignerLoading = (data: boolean) =>
    (this.addEditDesignerLoading = data);

  // 新增实验设计
  addDesigner = async (data: any) => {
    this.changeAddEditDesignerLoading(true);
    const res = await fetchAddDesigner(data);
    this.changeAddEditDesignerLoading(false);
    if (checkResonse(res)) {
      const { data } = res.data;
      this.changeCurrentDesigner(data);
      return data;
    }
    const { message } = res.data;
    return {
      msg: message,
    };
  };

  // 更新实验设计
  updateDesigner = async (data: any) => {
    this.changeAddEditDesignerLoading(true);
    const res = await fetchUpdateDesigner(data);
    this.changeAddEditDesignerLoading(false);
    if (checkResonse(res)) {
      const { data } = res.data;
      this.changeCurrentDesigner(data);
      return data;
    }
    const { message } = res.data;
    return {
      msg: message,
    };
  };

  // 所有实验设计
  allDesigner: ITDesinger[] = [];

  // 修改所有实验设计
  changeAllDesigner = (data: ITDesinger[]) => (this.allDesigner = data);

  // 所有实验设计请求状态
  allDesignerLoading: boolean = false;

  // 修改所有实验设计请求状态
  changeAllDesignerLoading = (data: boolean) =>
    (this.allDesignerLoading = data);

  // 请求所有实验设计
  getAllDesigner = async (): Promise<ITBadResp | null> => {
    this.changeAllDesignerLoading(true);
    const res = await fetchAllDesigner();
    this.changeAllDesignerLoading(false);
    if (checkResonse(res)) {
      const { data } = res.data;
      if (data && data.length) {
        data.forEach((item: any, index: number) => {
          item.key = index;
        });
        // 根据 Update time 重新排序,最新的在最前面
        data.sort((a: any, b: any) => {
          return b.updateTime - a.updateTime;
        });
      }
      this.changeAllDesigner(data);
    }
    const { message } = res.data;
    return {
      msg: message,
    };
  };

  getAllDesignerList = async (): Promise<ITBadResp | any[]> => {
    const res = await fetchAllDesigner();
    if (checkResonse(res)) {
      const { data } = res.data;
      return data;
    }
    return [];
  };

  // 删除设计请求状态
  delDesignerLoading: boolean = false;

  // 修改删除实验设计
  changeDelDesignerLoading = (data: boolean) =>
    (this.delDesignerLoading = data);

  // 删除实验设计
  delDesigner = async (data: any): Promise<ITBadResp | null> => {
    this.changeDelDesignerLoading(true);
    const res = await fetchDelDesigner(data);
    this.changeDelDesignerLoading(false);
    if (checkResonse(res)) {
      return null;
    }
    const { message } = res.data;
    return {
      msg: message,
    };
  };

  // 当前实验设计信息
  currentDesigner: ITDesinger | null = null;

  // 修改当前实验设计信息
  changeCurrentDesigner = (data: ITDesinger) => (this.currentDesigner = data);

  // 请求当前实验设计详情状态
  currentDesignerLoading: boolean = false;

  // 修改请求当前实验设计详情状态
  changgeCurrentDesignerLoading = (data: boolean) =>
    (this.currentDesignerLoading = data);

  // 当前反应试剂信息
  currentReactorReagents: ITDReactReagent[] = [];

  // 修改当前反应的试剂信息
  changeCurrentReagentorReagent = (data: ITDReactReagent[]) =>
    (this.currentReactorReagents = data);

  // 请求实验设计详情
  getDesignerInfo = async (data: any): Promise<ITBadResp | null> => {
    this.changgeCurrentDesignerLoading(true);
    const res = await fetchDesignerInfo(data);
    this.changgeCurrentDesignerLoading(false);
    if (checkResonse(res)) {
      const { data } = res.data;
      const tempData = sortDesignerStep(data);
      const { slotShelf, reactorSlotShelf, reagents, reactors = [] } = tempData;
      this.changeCurrentDesigner(tempData);
      this.changeCurrentSlotInfo(slotShelf);
      this.changeCurrentReactorSlotInfo(reactorSlotShelf);
      this.changeCurrentReagentsInfo(reagents);
      this.changeCurrentReagentorReagent(reactors);
      return null;
    }
    let message = "";
    if (res && res.data) {
      message = res.data.message;
    }
    return {
      msg: message,
    };
  };

  getDesignerDetail = async (data: any): Promise<ITDesinger | null> => {
    this.changgeCurrentDesignerLoading(true);
    const res = await fetchDesignerInfo(data);
    this.changgeCurrentDesignerLoading(false);
    if (checkResonse(res)) {
      const { data } = res.data;
      return data;
    }
    return null;
  };

  // 当前工作台信息
  currentWorkbench: ITWorkbench | null = null;

  // 修改当前工作台信息
  changeCurrentWorkbench = (data: ITWorkbench | null) =>
    (this.currentWorkbench = data);

  // 当前工作台插槽信息
  currentSlotInfo: any = {};

  // 修改当前工作台插槽信息
  changeCurrentSlotInfo = (data: any) => (this.currentSlotInfo = data);

  // 保存插槽使用的试管架
  saveSlotInfo = async (data: any): Promise<ITBadResp | null> => {
    const tempSlotInfo = {
      ...this.currentSlotInfo,
      ...data,
    };

    const param = {
      id: this.currentDesigner?.id,
      slotShelf: tempSlotInfo,
    };
    await this.updateDesigner(param);
    this.changeCurrentSlotInfo(tempSlotInfo);
    return null;
  };

  removeSlotInfo = async (slotname: string): Promise<ITBadResp | null> => {
    const keys = Object.keys(this.currentSlotInfo);
    let tempObj: any = null;
    if (keys && keys.length) {
      tempObj = {};
      keys.forEach((item) => {
        if (item !== slotname) {
          tempObj[item] = this.currentSlotInfo[item];
        }
      });
    }
    let param = Object.assign({}, this.currentDesigner, { slotShelf: tempObj });
    await this.updateDesigner(param);
    this.changeCurrentSlotInfo(tempObj);
    return null;
  };

  // 当前工作台反应台信息
  currentReactorSlotInfo: any = null;

  // 修改当前工作台反应台信息
  changeCurrentReactorSlotInfo = (data: any) =>
    (this.currentReactorSlotInfo = data);

  // 存储反应插槽信息
  saveReactorSlotInfo = async (data: any): Promise<ITBadResp | null> => {
    const param = Object.assign({}, this.currentDesigner, {
      reactorSlotShelf: data,
    });
    await this.updateDesigner(param);
    this.changeCurrentReactorSlotInfo(data);
    return null;
  };

  // 清除插槽信息
  removeReactorSlotInfo = async (): Promise<ITBadResp | null> => {
    const param = Object.assign({}, this.currentDesigner, {
      reactorSlotShelf: {},
    });
    await this.updateDesigner(param);
    this.changeCurrentReactorSlotInfo({});
    return null;
  };

  // 当前实验设计试剂信息
  /**
   * reagents: {
      [slotname]: {
        [bottleName]: {
          reagentId: string
          amount: number
        }
      }
   * }
   */
  currentReagentsInfo: ITDesignerReagent | null = null;

  // 修改当前实验设计试剂信息
  changeCurrentReagentsInfo = (data: ITDesignerReagent | null) =>
    (this.currentReagentsInfo = data);

  // 保存试剂请求状态
  addEditReagentLoading: boolean = false;

  // 修改保存试剂请求状态
  changeAddEditReagentLoading = (data: boolean) =>
    (this.addEditReagentLoading = data);

  // 新增试剂信息
  addReagents = async (data: any): Promise<ITBadResp | null> => {
    this.changeAddEditReagentLoading(true);
    const res = await fetchAddDesignerReagent(data);
    this.changeAddEditReagentLoading(false);
    if (checkResonse(res)) {
      await this.getDesignerInfo({ id: this.currentDesigner?.id });
    }
    return null;
  };

  // 更新试剂信息
  updateReagents = async (data: any): Promise<ITBadResp | null> => {
    this.changeAddEditReagentLoading(true);
    const res = await fetchUpdateDesignerReagent(data);
    this.changeAddEditReagentLoading(false);
    if (checkResonse(res)) {
      this.getDesignerInfo({ id: this.currentDesigner?.id });
    }
    return null;
  };

  // 清除试剂信息
  removeReagent = async (data: any): Promise<ITBadResp | null> => {
    const res = await fetchDelDesignerReagent(data);
    if (checkResonse(res)) {
      this.getDesignerInfo({ id: this.currentDesigner?.id });
    }
    return null;
  };

  // 新增，修改，删除反应试剂请求状态
  reactorReagentLoading: boolean = false;

  // 修改新增，修改，删除反应试剂请求状态
  changeReactorReagentLoading = (data: boolean) =>
    (this.reactorReagentLoading = data);

  // 新增反应试剂信息
  //   addReactorReagent = async (data: any): Promise<ITBadResp | null> => {
  //     this.changeReactorReagentLoading(true);
  //     const res = await fetchAddReactorReagent(data);
  //     this.changeReactorReagentLoading(false);
  //     if (checkResonse(res)) {
  //       await this.getDesignerInfo({ id: this.currentDesigner?.id });
  //     }

  //     return null;
  //   };

  // 清除实验试剂
  clearReactorReagen = async (data: any): Promise<ITBadResp | null> => {
    this.changeReactorReagentLoading(true);
    const res = await fetchClearDesignerReactorReagent(data);
    this.changeReactorReagentLoading(false);
    if (checkResonse(res)) {
      await this.getDesignerInfo({ id: this.currentDesigner?.id });
    }
    return null;
  };

  // 删除反应试剂
  delDataReactorReagent = async (data: any): Promise<ITBadResp | null> => {
    this.changeReactorReagentLoading(true);
    const res = await fetchDeleteDesignerReactorReagent(data);
    this.changeReactorReagentLoading(false);
    if (checkResonse(res)) {
      await this.getDesignerInfo({ id: this.currentDesigner?.id });
    }
    return null;
  };

  // 编辑反应试剂
  updateReactorReagent = async (data: any): Promise<ITBadResp | null> => {
    this.changeReactorReagentLoading(true);
    const res = await fetchUpdateReactorReagent(data);
    this.changeReactorReagentLoading(false);
    if (checkResonse(res)) {
      await this.getDesignerInfo({ id: this.currentDesigner?.id });
    }
    return null;
  };

  // 复制反应试剂
  copyReactorReagent = async (data: any): Promise<ITBadResp | null> => {
    this.changeReactorReagentLoading(true);
    const res = await fetchCopyReactorReagent(data);
    this.changeReactorReagentLoading(false);
    if (checkResonse(res)) {
      await this.getDesignerInfo({ id: this.currentDesigner?.id });
    }
    return null;
  };

  // 是否显示添加，编辑试剂弹窗
  showReagentAddEditModal: boolean = false;

  // 修改是否显示添加，编辑试剂弹窗
  changShowReagentAddEditModal = (data: boolean) =>
    (this.showReagentAddEditModal = data);

  // 添加，编辑试剂弹窗信息
  reagentAddEditData: any = null;

  // 修改添加，编辑试剂弹窗信息
  changeReagentAddEditData = (data: any) => (this.reagentAddEditData = data);

  // 是否显示编辑反应试剂弹窗
  showReactorReagentDataModal = false;

  // 修改是否显示编辑反应试剂弹窗
  changeShowReactorReagentDataModal = (data: boolean) =>
    (this.showReactorReagentDataModal = data);

  // 编辑的反应试剂信息
  editReactorReagentData: ITDReactReagent | null = null;

  // 修改编辑的反应试剂信息
  changeEditReactorReagentData = (data: ITDReactReagent | null) =>
    (this.editReactorReagentData = data);

  // 显示实验详情drawer
  showDesingerDetail = false;

  // 修改显示实验详情drawer
  changeShowDesingerDetail = (data: boolean) =>
    (this.showDesingerDetail = data);

  // 计算反应试剂信息
  get reactorReagents() {
    let temp: ITReactorReagent[] = [];
    if (this.currentReagentsInfo) {
      let tempObj: any = {};
      const slotReagents = { ...this.currentReagentsInfo };
      const slots = Object.keys(slotReagents);
      if (slots && slots.length) {
        slots.forEach((slotName: string) => {
          const bottleObj = slotReagents[slotName];
          const bottles = Object.keys(bottleObj);
          if (bottles && bottles.length) {
            bottles.forEach((bottleName: string) => {
              const reagentInfo = bottleObj[bottleName];
              const { reagentId, mmol, volume, weight, type } = reagentInfo;
              if (tempObj[reagentId]) {
                temp.some((item: any) => {
                  if (item.id === reagentId) {
                    if (
                      mmol > 0 &&
                      item.mmol !== null &&
                      item.mmol !== undefined
                    ) {
                      let tempMmol: any = math.format(
                        math.evaluate(`${item.mmol} + ${mmol}`),
                        FIXEDINDEX
                      );
                      item.mmol = tempMmol - 0;
                    }
                    if (
                      weight > 0 &&
                      item.weight !== null &&
                      item.weight !== undefined
                    ) {
                      let tempWeight: any = math.format(
                        math.evaluate(`${item.weight} + ${weight}`),
                        FIXEDINDEX
                      );
                      item.weight = tempWeight - 0;
                    }
                    if (
                      volume > 0 &&
                      item.volume !== null &&
                      item.volume !== undefined
                    ) {
                      let tempVolume: any = math.format(
                        math.evaluate(`${item.volume} + ${volume}`),
                        FIXEDINDEX
                      );
                      item.volume = tempVolume - 0;
                    }
                    return true;
                  }
                  return false;
                });
              } else {
                tempObj[reagentId] = true;
                temp.push({
                  id: reagentId,
                  mmol,
                  volume,
                  weight,
                  type,
                });
              }
            });
          }
        });
      }
    }
    return temp;
  }

  // 导出实验数据
  exportDesinger = async (
    data: any,
    callback: () => void
  ): Promise<ITBadResp | null> => {
    const res = await fetchExportDesigner(data);
    if (checkResonse(res)) {
      const { fileName } = res.data;
      const { protocol, host } = window.location;
      const href = `${protocol}//${host}/project/${fileName}`;
      const a = document.createElement("a");
      let timeOut: any = setTimeout(() => {
        a.setAttribute("href", href);
        document.body.appendChild(a);
        a.click();
        clearTimeout(timeOut);
        timeOut = null;
        callback();
      }, 2000);
    }
    return null;
  };

  // 复制实验设计
  copyDesigner = async (data: any): Promise<ITBadResp | null> => {
    const res = await fetchCopyDesigner(data);
    if (checkResonse(res)) {
      return null;
    }
    const { message } = res.data;
    return {
      msg: message,
    };
  };

  // 修改反应步骤
  changeReactorStep = async (data: any): Promise<ITBadResp | null> => {
    const res = await fetchReactorStep(data);
    if (checkResonse(res)) {
      return null;
    }
    const { message } = res.data;
    return {
      msg: message,
    };
  };

  createReactorExcel = async (
    data: any,
    callback?: () => void
  ): Promise<ITBadResp | null> => {
    const res = await fetchCreateReactExcel(data);
    if (checkResonse(res)) {
      const { fileName } = res.data;
      const { protocol, host } = window.location;
      const href = `${protocol}//${host}/project/${fileName}`;
      const a = document.createElement("a");
      let timeOut: any = setTimeout(() => {
        a.setAttribute("href", href);
        document.body.appendChild(a);
        a.click();
        clearTimeout(timeOut);
        timeOut = null;
      }, 2000);
    }
    return null;
  };

  // 新增反应设计
  createReactDesigner = async (data: any): Promise<ITBadResp | null> => {
    const res = await fetchCreateReactDesigner(data);
    if (checkResonse(res)) {
      return res.data?.data;
    }
    return null;
  };

  // 删除反应设计
  delReactDesigner = async (data: any): Promise<ITBadResp | null> => {
    const res = await fetchDelReactDesigner(data);
    if (checkResonse(res)) {
      return null;
    }
    const { message } = res.data;
    return {
      msg: message,
    };
  };

  // 更新反应设计
  updateReactDesigner = async (data: any): Promise<ITBadResp | null> => {
    const res = await fetchUpdateReactDesigner(data);
    if (checkResonse(res)) {
      return null;
    }
    const { message } = res.data;
    return {
      msg: message,
    };
  };

  getReactDesignById = async (data: any): Promise<ITBadResp | any> => {
    const res = await fetchGetReactDesignerById(data);
    if (checkResonse(res)) {
      return res.data?.data;
    }
  };

  reactionDesignerList = [];
  changeReactionDesignerList = (data: any) =>
    (this.reactionDesignerList = data);

  getReactDesignerList = async (data: any): Promise<ITBadResp | any[]> => {
    const res = await fetchReactDesignerList(data);
    if (checkResonse(res)) {
      const { data } = res.data;
      if (data && data.length) {
        data.forEach((item: any, index: number) => {
          item.key = index;
        });
        // 反转数组
        data.reverse();
      }
      this.changeReactionDesignerList(data);
    }
    return [];
  };

  openReactionDrawer = false;
  changeOpenReactionDrawer = (open: boolean) => {
    this.openReactionDrawer = open;
  };

  reactionDrawerData = null;
  changeReactionDrawerData = (data: any) => (this.reactionDrawerData = data);
}

const designerStore: ITDesignerStore = new DesignerStore();
export default designerStore;
